package main

import (
	"log"

	dbCli "pan/service/dbproxy/client"
	"pan/service/user/handler"
	proto "pan/service/user/proto"

	"github.com/go-micro/plugins/v4/registry/consul"
	"go-micro.dev/v4"
	"go-micro.dev/v4/registry"
)

func main() {
	consulRegistry := consul.NewRegistry(registry.Addrs("127.0.0.1:8500"))
	service := micro.NewService(
		micro.Name("user"),
		micro.Version("latest"),
		// micro.RegisterTTL(time.Second*10),     // TTL指定从上一次心跳间隔起，超过这个时间服务会被服务发现移除
		// micro.RegisterInterval(time.Second*5), // 让服务在指定时间内重新注册，保持TTL获取的注册时间有效
		micro.Registry(consulRegistry),
	)
	// 初始化service, 解析命令行参数等
	service.Init()
	// 初始化dbproxy client
	dbCli.Init(service)
	proto.RegisterUserServiceHandler(service.Server(), new(handler.User))
	if err := service.Run(); err != nil {
		log.Println(err)
	}
}
